#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "../include/unicom.h"
#include "../include/tty.h"
/*
 *tty显示环境信息
 **/
void display_env(struct sendEnv *house_env)
{
	int i;
	system("clear");

	puts("------------------ENV---------------------");
	fprintf(stderr, "Head    :  ");
	for (i = 0; i < 3; i++)
		putchar(house_env->head[i]);
	putchar('\n');

	fprintf(stderr, "Type    :  %c\n", house_env->type);
	fprintf(stderr, "StrNo   :  %u\n", house_env->snum);

	fprintf(stderr, "Temp(C) :  %d.%d\n", house_env->temp[0], house_env->temp[1]);
	fprintf(stderr, "Hum(%%)  :  %d.%d\n", house_env->hum[0], house_env->hum[1]);

	fprintf(stderr, "X       :  %u\n", house_env->x);
	fprintf(stderr, "Y       :  %u\n", house_env->y);
	fprintf(stderr, "Z       :  %u\n", house_env->z);
	fprintf(stderr, "Ill     :  %u\n", house_env->ill);
	fprintf(stderr, "Bat     :  %u\n", house_env->bat);
	fprintf(stderr, "Adc     :  %u\n", house_env->adc);
	puts("------------------------------------------");
}

/*
 *tty显示货物信息
 **/
void display_rfid(struct sendGoods *house_goods)
{
	char IO[10] = {0};
	char Thing[10] = {0};
	int i;

	puts("##################GOODS##################");
	fprintf(stderr, "Head     :  ");
	for (i = 0; i < 3; i++)
		putchar(house_goods->head[i]);
	putchar('\n');

	fprintf(stderr, "Type     :  %c\n", house_goods->type);

	fprintf(stderr, "StrNo    :  %u\n", house_goods->snum);

	if (house_goods->io == 79)
	{
		strcpy(IO, "Out");
	}
	else if (house_goods->io == 73)
	{
		strcpy(IO, "In");
	}
	fprintf(stderr, "I/O      :  %s\n", IO);

	switch (house_goods->goodsno)
	{
	case 1:
		strcpy(Thing, "apple");
		break;
	case 2:
		strcpy(Thing, "Banana");
		break;
	case 3:
		strcpy(Thing, "Pear");
		break;
	case 4:
		strcpy(Thing, "Kiwi");
		break;
	case 5:
		strcpy(Thing, "Mango");
		break;
	case 6:
		strcpy(Thing, "Pitaya");
		break;
	case 7:
		strcpy(Thing, "Orange");
		break;
	default:
		strcpy(Thing, "Unknown");
		break;
	}
	fprintf(stderr, "GoodsNo  :  %u, Is %s\n", house_goods->goodsno, Thing);

	fprintf(stderr, "GoodsNum :  %u\n", house_goods->goodsnum);

	puts("########################################");
}